angular.module('U9ImPDA.services')

.factory('isSanner', ['$q', '$rootScope', 'imanDialog', function($q, $rootScope, imanDialog) {

    document.addEventListener('iScanner.DataReceived', function(e) {
        $rootScope.$broadcast('iScanner.DataReceived', e.scanData);
    }, false);

    return {
        open: openSanner,
        close: closeSanner
    };

    function openSanner() {
        if (window.cordova && cordova.plugins.iscanner) {
            cordova.plugins.iscanner.open();
        }
    }

    function closeSanner() {
        if (window.cordova && cordova.plugins.iscanner) {
            cordova.plugins.iscanner.close();
        }
    }
}]);
